package com.home766.controller.admin;

import com.home766.dto.DictionaryDTO;
import com.home766.entity.CustomerService;
import com.home766.service.CustomerSvService;
import com.home766.service.IDictionaryService;
import net.biz.Message;
import net.biz.Page;
import net.biz.Pageable;
import net.biz.controller.admin.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/admin/customerService")
public class CustomerServiceController extends BaseController {
	@Resource(name="customerSvServiceImpl")
	private CustomerSvService customerSvService;
	@Resource(name="dictionaryServiceImpl")
	private IDictionaryService iDictionaryService;
	
	/****
	 * 列表
	 * @param customerService
	 * @param pageable
	 * @param modelMap
	 * @param sort
	 * @param properties
	 * @return
	 */
	@RequestMapping("/list")
	public String customerServicePage(CustomerService customerService, Pageable pageable, ModelMap modelMap, String sort, String properties){
		List<DictionaryDTO> dc = iDictionaryService.searchChildren(88L);
		Page<CustomerService> page = customerSvService.findList(customerService, pageable, properties);
		modelMap.addAttribute("page",page);
		modelMap.addAttribute("dc",dc);
		return "/admin/customer_service/list";
	}
	/***
	 * 批量删除
	 * @param id
	 * @param redirectAttributes
	 * @return
	 */
	@RequestMapping("/delete")
	public String delete(Long id[], RedirectAttributes redirectAttributes){
		for(Long i : id){
			customerSvService.delete(i);
			addFlashMessage(redirectAttributes,new Message(Message.Type.success,"删除成功"));
		}
		return "redirect:list.jhtml";
	}
	/***
	 * 修改处理状态
	 * @param id
	 * @param redirectAttributes
	 * @return
	 */
	@RequestMapping("/update")
	public String update(Long id, Long handlePeople, RedirectAttributes redirectAttributes){
		CustomerService customerService = customerSvService.find(id);
		customerService.setHandle(1);
		customerService.setHandlePeople(handlePeople);
		customerSvService.update(customerService);
		addFlashMessage(redirectAttributes,new Message(Message.Type.success,"修改成功"));
		return "redirect:list.jhtml";
	}
	/***
	 * 查看
	 * @param id
	 * @param modelMap
	 * @return
	 */
	@RequestMapping("/view")
	public String view(Long id, ModelMap modelMap){
		CustomerService customerService = customerSvService.find(id);
		modelMap.addAttribute("customerService",customerService);
		return "/admin/customer_service/view";
	}
}
